package com.ruoyi.service;

import com.ruoyi.dto.ResponseDTO;
import com.ruoyi.mapper.CouponMapper;
import com.ruoyi.pojo.Coupons;
import com.ruoyi.povo.CouponsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CouponServiceImpl implements CouponService{
    @Autowired
    private CouponMapper couponMapper;
    @Override
    public ResponseDTO getAllCoupons() {
        List<Coupons> coupons=couponMapper.getAllCoupons();
        return ResponseDTO.success(coupons);
    }

    @Override
    public ResponseDTO addCoupon(CouponsVo couponsVo) {
        int res=couponMapper.addCouPon(couponsVo);
        if(res>0){
            return ResponseDTO.success(res);
        }
        else{
            return ResponseDTO.error("添加失败");
        }
    }

    @Override
    public ResponseDTO editCoupon(CouponsVo couponsVo) {
        int res=couponMapper.editCoupon(couponsVo);
        if(res>0){
            return ResponseDTO.success(res);
        }
        else{
            return ResponseDTO.error("添加失败");
        }
    }

    @Override
    public ResponseDTO changeCoupon(String id, String status) {

        int res=couponMapper.changeCoupon(id,status);
        if(res>0){
            if(status.equals("0")){
                return ResponseDTO.success("开启成功");
            }
            else{
                return ResponseDTO.success("禁用成功");
            }
        }
        else{
            if(status.equals("0")){
                return ResponseDTO.success("开启失败");
            }
            else{
                return ResponseDTO.success("禁用失败");
            }
        }
    }
}
